using System;
using System.Collections;
using System.Drawing;
using System.ComponentModel;
using System.Windows.Forms;

namespace asWins.Forms
{
	/// <summary>
	/// Summary description for asTabCollection.
	/// </summary>
	public class asTabFormCollection : CollectionBase
	{
		/// <summary>
		/// Initialized and set parent too.
		/// </summary>
		/// <param name="parent"></param>
		public asTabFormCollection(asMdiManager parent)
		{
			this.m_Parent = null;
			this.m_Parent = parent;
		}

		private asMdiManager m_Parent;
		/// <summary>
		/// Property Parent (asMdiManager)
		/// </summary>
		public asMdiManager Parent
		{
			get {return m_Parent;}
			set {m_Parent = value;}
		}

		/// <summary>
		/// Get asTabForm from index.
		/// </summary>
		public asTabForm this[int index]
		{
			get
			{
				return List[index] as asTabForm;
			}
		}

		/// <summary>
		/// Get asTabForm by FormId.
		/// Return asTabForm if found otherwise return null.
		/// </summary>
		/// <param name="formId"></param>
		/// <returns></returns>
		public asTabForm FindTab(int formId)
		{
			asTabForm tab = null;
			int nIndex = this.GetTabIndex(formId);
			if ( (nIndex >-1) && (nIndex<List.Count) )
			{
				tab = this[nIndex];
			}
			return tab;
		}

		/// <summary>
		/// Get index form FormID.
		/// </summary>
		/// <param name="formId"></param>
		/// <returns></returns>
		public int GetTabIndex(int formId)
		{
			int index = -1;
			for (int i=0; i<this.Count; i++)
			{
				if (this[i].FormId == formId)
				{
					index = i;
					break;
				}
			}
			return index;
		}

		/// <summary>
		/// Reset all TabForm to false.
		/// </summary>
		public void ResetActiveTabForms()
		{
			foreach (asTabForm tab in List)
			{
				tab.IsActive = false;
				tab.OwnerForm.Dock = DockStyle.None;
			}
		}

		/// <summary>
		/// Add asTabForm.
		/// </summary>
		/// <param name="tab"></param>
		public void Add(asTabForm tab)
		{
			List.Add(tab);
		}

		/// <summary>
		/// Remove asTabForm.
		/// </summary>
		/// <param name="tab"></param>
		public void Remove(asTabForm tab)
		{
			List.Remove(tab);
		}

		/// <summary>
		/// Clear all members tab and owner from in List.
		/// </summary>
		public new void Clear()
		{
			foreach (asTabForm tab in List)
			{
				if (tab.OwnerForm != null)
				{
					tab.OwnerForm.Dispose();
				}
			}
			List.Clear();
		}

		/// <summary>
		/// Get Total tab width.
		/// </summary>
		public int Width
		{
			get
			{
				int nTotalWidth = 0;
				for (int i=0; i<List.Count; i++)
				{
					asTabForm tab = (asTabForm)List[i];
					nTotalWidth += tab.Width;
				}
				return nTotalWidth;
			}
		}



	}
}
